<?php

namespace Home\Model;

use Think\Model;

class UserModel extends Model
{
    protected $trueTableName = "think_user";

    protected $_validate = array(
        array('name', 'require', '请填写昵称！'),
        array('name', '', '此昵称已经存在,请不要重复添加！', 1, 'unique', 1),
//        array('role_id', 'require', '请选择部门！'),
        array('phone', 'require', '请选择手机！'),
        array('phone', '', '该手机已经存在！', 1, 'unique', 1),
        array('account', 'require', '请填写账号！'),
        array('account', '', '该账号已经存在！', 1, 'unique', 1),
        array('avatar', 'require', '头像必须上传'),
    );

    public function check_login($account, $password)
    {
        $password = md5($password);
        $opt['account'] = array('eq', $account);
        $opt['password'] = array('eq', $password);
        return $this->where($opt)->find();
    }

    public function updateTime($id)
    {
        $data['update_time'] = date('Y-m-d H:i:s');
        $this->where("id = {$id}")->save($data);
    }

    public function insert($data = array())
    {
        return $this->add($data);
    }

    public function getAllByLimit($opt, $page, $pageSize)
    {
        $data = $this->where($opt)->page($page, $pageSize)->select();
        $count = $this->where($opt)->count();
        return array('data' => $data, 'count' => $count);

    }
}